/**
 * @Date: Mar 8, 2010 8:07:06 PM
 */
package com.philip.journal.home.controller.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;

import com.philip.core.WarningType;
import com.philip.journal.core.controller.ResponseHandler;
import com.philip.journal.core.exception.JournalException;
import com.philip.journal.core.service.ServiceProxy;
import com.philip.journal.home.bean.Category;

/**
 * @author cry30
 */
public class GetCategoriesAction extends AbstractTreeAction {

    /** Property name for VIEW list. */
    private static final String ROWS = "rows";

    /**
     * Default delegate constructor.
     *
     * @param serviceProxy Service proxy to be injected by Spring.
     * @param responseHandler Response handler to be injected by Spring.
     */
    public GetCategoriesAction(final ServiceProxy serviceProxy, final  ResponseHandler responseHandler) {
        super(serviceProxy, responseHandler);
    }

    @Override
    public void execute() throws ServletException, IOException {
        try {
            @SuppressWarnings(WarningType.DEPRECATION)
            final List<Category> categories = getServiceProxy().getCategories();
            getResponseHandler().respondListHolder(getHttpServletResponse(), categories, ROWS);
        } catch (final JournalException e) {
            getLogger().debug(e.getMessage(), e);
            getResponseHandler().respondFail(getHttpServletResponse(), e.getMessage());
        }
    }
}
